//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "CDBCombo.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
#define COL_DISABLE clBtnFace
//---------------------------------------------------------------------------
// ValidCtrCheck est utilisé pour être sûr que les composants créés ne
// contiennent aucune fonction virtuelle pure.
//

static inline void ValidCtrCheck(CDBComboBox *)
{
    new CDBComboBox(NULL);
}
//---------------------------------------------------------------------------
__fastcall CDBComboBox::CDBComboBox(TComponent* Owner)
    : TDBComboBox(Owner)
{
  m_asRefWebHelp               = EmptyStr;
  m_Enabled                    = true;
  m_ReadOnly                   = false;
  m_Label                      = NULL;
  m_LibelleFont                = NULL;
  m_Libelle                    = EmptyStr;
  m_SizeEspace                 = 10;
  m_pfnOnEstCorrectementRempli = NULL;

  try {
    m_Label               = new TLabel(this);
    m_LibelleFont         = new TFont;
    m_LibelleFont->OnChange = SetLibelleFontChange;
    m_Label->Transparent  = true;
    m_Label->Visible      = false;
    m_Label->Caption      = m_Libelle;
    m_Label->Enabled      = Enabled;
    m_Label->FocusControl = this;
  } catch (...) {
  }
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::SetEnabled(bool value)
{
  if ( m_Label) m_Label->Enabled = value;
  m_Enabled            = value;
  TDBComboBox::Enabled = value;
  RafraichirFond(this);
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::SetReadOnly(bool value)
{
  m_ReadOnly            = value;
  TDBComboBox::ReadOnly = value;
  RafraichirFond(this);
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::SetLibelle(const AnsiString value)
{
  m_Libelle        = value;
  m_Label->Caption = value; SetLibellePos();
  m_Label->Visible = (value!=EmptyStr);
  if (!m_Label->Parent) m_Label->Parent = Parent;
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::SetLibellePos()
{
  m_Label->Top  = Top + ((Height - m_Label->Height - 2) >> 1);
  m_Label->Left = Left - m_Label->Width - m_SizeEspace;
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::SetSizeEspace(int value)
{
  m_SizeEspace = value;
  SetLibellePos();
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::SetLibelleFont(TFont *value)
{
  m_LibelleFont->Assign(value);
  m_LibelleFont->PixelsPerInch = value->PixelsPerInch;
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::SetLibelleFontChange(TObject *Sender)
{
  m_Label->Font->Assign(m_LibelleFont);
  m_Label->Font->PixelsPerInch = m_LibelleFont->PixelsPerInch;
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::Change( void)
{
  RafraichirFond(this);
  TDBComboBox::Change();
}
bool __fastcall CDBComboBox::EstCorrectementRempliDefault( void)
{
  return( ItemIndex != -1);
}
void __fastcall CDBComboBox::SetObligatoire( bool bObligatoire)
{
  m_Obligatoire = bObligatoire;
  RafraichirFond(this);
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::WMWindowPosChanged(TWMWindowPosChanged &Msg)
{
  TDBComboBox::Dispatch(&Msg);
  SetLibellePos();
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::WndProc( TMessage &Message)
{
  if (( Message.Msg==WM_SETFOCUS) && m_ReadOnly) { Message.Msg = WM_NULL; ::SetFocus( Parent->Handle); }
  TDBComboBox::WndProc( Message);
}
//---------------------------------------------------------------------------
namespace Cdbcombo
{
    void __fastcall PACKAGE Register()
    {
        TComponentClass classes[1] = {__classid(CDBComboBox)};
        RegisterComponents("EIC CtrlDB", classes, 0);
    }
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::SetBleuSiHint( bool bBleuSiHint)
{
  m_BleuSiHint = bBleuSiHint;
  RafraichirFond(this);
}
//---------------------------------------------------------------------------
void __fastcall CDBComboBox::KeyDown( Word &Key, TShiftState Shift)
{
    if( Key == VK_F3 )
        VerifierRefWebHelp( m_asRefWebHelp );
}
//---------------------------------------------------------------------------
